package com.siysoft.tc.admin.service.Impl;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.siysoft.tc.admin.service.IAdminMessageService;
import com.siysoft.tc.base.bean.to.MsgArticle;
import com.siysoft.tc.base.bean.to.MsgArticleToRead;
import com.siysoft.tc.base.bean.to.User;
import com.siysoft.util.IMap;
import com.tc.base.dao.BaseDAO;

/**
 * 方法摘要：实现后台管理员视频记录功能接口 作者：zhouyu 日期：2015年6月10日
 * 
 * @param iMap
 * @return
 * @throws Exception
 */
@Service
public class AdminMessageServiceImpl implements IAdminMessageService {
	
	@Autowired
	BaseDAO baseDao;

	@Override
	public List<Map<String, Object>> seekMessages(IMap iMap) throws Exception {
		// TODO Auto-generated method stub
		String hql = "select * from db_msg_article";
		return (List<Map<String, Object>>) baseDao.findBySQLToMap(hql, null, -1, -1);
	}

	@Override
	public List<Map<String, Object>> seekUserMessages(IMap iMap)
			throws Exception {
		// TODO Auto-generated method stub
		String hql = "select * from v_message where message_id = " + iMap.getInt("id");
		return (List<Map<String, Object>>) baseDao.findBySQLToMap(hql, null, -1, -1);
	}

	@Override
	public void addMessage(IMap iMap) {
		// TODO Auto-generated method stub
		//type: 1:系统消息 2:课程消息 11.系统文章
		MsgArticle msg = new MsgArticle(iMap.getString("content"), 
				iMap.getString("content"), "", 1, new Timestamp(System.currentTimeMillis()));
		Integer msg_id = (Integer) baseDao.saveReturnId(msg);
		
		String hql = "from User";
		List<User> user_list = (List<User>)baseDao.findByHQL(hql);
		for (User user : user_list) {
			MsgArticleToRead msg_to_read = new MsgArticleToRead(String.valueOf(msg_id), String.valueOf(user.getUser_id()), "0");
			baseDao.save(msg_to_read);
		}
		return;
	}

	
	
}
